package demo3;

class Animal {
    public String name;
    public int age;
     public void eat() {
         System.out.println("吃饭！");
     }
}
class Cat extends Animal {
    public String color;
    public void eat() {
        System.out.println(name + " 正在吃猫粮！");
    }
}

class Dog extends Animal {
    public void eat() {
        System.out.println(name + " 正在吃狗粮！");
    }
}

public class Test {
    public static void func1(Animal animal) {
        animal.eat();

    }
    public static Animal func2() {
        //return new Animal();
        Cat cat = new Cat();
        Dog dog = new Dog();
        return dog;
    }
    public static Cat func3() {
        //return new Animal();
        Cat cat = new Cat();
        return cat;
    }

    public static void main(String[] args) {
        Animal animal = func3();
    }
    public static void main2(String[] args) {
        Cat cat = new Cat();
        Dog dog = new Dog();
        func1(cat);
        func1(dog);
    }
    public static void main1(String[] args) {
        Animal animal = new Cat();
        animal.eat();//动态绑定
        //animal.color();
    }
}
